package com.mdd.front.service.system.impl;

import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.github.yulichang.query.MPJQueryWrapper;
import com.mdd.common.config.GlobalConfig;
import com.mdd.common.entity.system.SystemDevPayWay;
import com.mdd.common.mapper.system.SystemDevPayWayMapper;
import com.mdd.common.utils.UrlUtil;
import com.mdd.front.service.system.ISystemDevPayWayService;
import com.mdd.front.vo.system.SystemDevPayWayDetailVo;
import org.springframework.beans.BeanUtils;
import org.springframework.stereotype.Service;
import org.springframework.util.Assert;

import javax.annotation.Resource;
import java.util.*;

/**
 * 支付方式实现类
 * @author panweiliang
 */
@Service
public class SystemDevPayWayServiceImpl implements ISystemDevPayWayService {
        
    @Resource
    SystemDevPayWayMapper systemDevPayWayMapper;

    /**
     * 支付方式列表
     *
     * @author panweiliang
     * @return List<SystemDevPayWayListVo>
     */
    @Override
    public List<SystemDevPayWayDetailVo> list(Integer scene, Integer hidePayWay) {

        MPJQueryWrapper<SystemDevPayWay> mpjQueryWrapper = new MPJQueryWrapper<SystemDevPayWay>()
                .selectAll(SystemDevPayWay.class)
                .select("pay.name as payName, pay.image as payImage, pay.pay_way as payWay")
                .innerJoin("?_dev_pay pay ON pay.id=t.pay_id".replace("?_", GlobalConfig.knowledgePaymentTablePrefixe))
                .eq("t.status", "1")
                .eq("t.scene", scene)
                .orderByDesc(Arrays.asList("t.id"));


        if (hidePayWay != null) {
            mpjQueryWrapper.ne("pay.pay_way", hidePayWay);
        }
        List<SystemDevPayWayDetailVo> list = systemDevPayWayMapper.selectJoinList(SystemDevPayWayDetailVo.class, mpjQueryWrapper);

        //场景:1-微信小程序;2-微信公众号;3-H5;4-PC商城;5-APP;
        list.forEach(item -> {
            item.setPayImage(UrlUtil.toAbsoluteUrl(item.getPayImage()));
        });

        return list;
    }
}
